package com.xdap.init.service.impl;

import com.xdap.init.dao.ModelDao;
import com.xdap.init.pojo.po.DataModel;
import com.xdap.init.service.TableIndexServiceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class TableIndexServiceServiceImpl implements TableIndexServiceService {

    @Autowired
    private ModelDao modelDao;

    @Override
    public String init() {
        // 数据库里面加了呀
        List<DataModel> allModel = modelDao.getAllModel();
        String result = "";
        //ALTER TABLE `gx_scheme_declaration` ADD KEY `document_id`(`document_id`) USING BTREE;
        for (DataModel dm : allModel) {
            String modelCode = dm.getModelCode();
            result += "ALTER TABLE `" + modelCode + "` ADD UNIQUE INDEX  `document_id`(`document_id`) USING BTREE;\n";
            result += "ALTER TABLE `" + modelCode + "` ADD KEY `tab_doc_id`(`tab_doc_id`) USING BTREE;\n";
            result += "\n";
        }

        result += "ALTER TABLE `xdap_watercode_stream ` ADD KEY `index_wcl`(`water_rule_id`,`component_id`," +
                "last_update_date ) USING BTREE;\n";
        result += "ALTER TABLE `xdap_watercode_stream ` ADD KEY `index_wc`(`water_rule_id`,`component_id`) USING BTREE;\n";
        result += "ALTER TABLE `xdap_watercode_stream ` ADD KEY `index_wcd`(`water_rule_id`,`component_id`,document_id ) USING BTREE;\n";
        result += "ALTER TABLE `xdap_watercode_stream ` ADD KEY `index_wcdl`(`water_rule_id`,`component_id`,document_id,last_update_date  ) USING BTREE;\n";
        result += "create index crm_follow_up_records_rela_bo_cust_id1 on crm_follow_up_records (rela_bo_cust_id desc);\n" +
                "create index crm_follow_up_records_rela_bo_cust_id2 on crm_follow_up_records (rela_bo_cust_id desc);\n" +
                "create index crm_follow_up_records_rela_bo_cust_id3 on crm_follow_up_records (rela_bo_cust_id desc);\n" +
                "create index process_bo_cust_ida_b on crm_follow_up_records (rela_bo_cust_id desc);\n" +
                "create index process_bo_cust_ida_b_c on crm_follow_up_records (rela_bo_cust_id desc);\n" +
                "create index process_bo_cust_ida_b_c_d on crm_follow_up_records (rela_bo_cust_id desca,b,c,d);\n";
        result += "create index index_apaas_data_model_model_code on apaas_data_model (model_code desc)\n";



      //  result += "ALTER TABLE `ACT_RE_DEPLOYMENT` ADD KEY `NAME_KEY_DEPLOY_TIME_`(`KEY_`, `NAME_`, `DEPLOY_TIME_`)
        //  USING BTREE;\n";


        //   result +="ALTER TABLE `xdap_activiti_295249621687468033`.`act_re_procdef` ADD INDEX `idx_DEPLOYMENTID` " +
        //           "(`DEPLOYMENT_ID_`)\n";
        result += "\n";
        result += "\n";
        result += "\n";
        result += "\n";
        result += "\n";
        result += "\n";
        result += "\n";


        return result;
    }
}
